﻿using System;

class MyStack<T>
{
    public T[] items;
    private int top;
    public MyStack(int capacity)
    {
        items = new T[capacity];
        top = 0;
    }
    public void InitStack()
    {
        top = 0;
    }
    public void ClearStack()
    {
        top = 0;
    }

    public bool Push(T item)
    {
        if (top == items.Length)
        {
            return false;
        }
        items[top] = item;
        top++;
        return true;
    }
    public T Pop()
    {
        if (top == 0)
        {
            throw new InvalidOperationException("栈为空，无法出栈");
        }
        top--;
        return items[top];
    }
}